<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/axios.js"></script>
</head>
<body>
    <form action="">
        <p>
            用户名:<input name="uname" type="text">
        </p>
        <p>
            密 码:<input name="upwd" type="password">
        </p>
        <p>
            <button>登录</button>
        </p>
    </form>

    <script>
        axios.defaults.headers.post["Content-Type"]="application/x-www-form-urlencoded";
        axios.defaults.baseURL="http://useker.cn";
        document.forms[0].onsubmit=function(){
            var oUser={
                uname:this.uname.value,
                upwd:this.upwd.value
            }

            axios.post("/login",oUser).then((res)=>{
                console.log(res);
                if(res.data.code==1){
                    alert("登录成功!")
                    sessionStorage.setItem("user",JSON.stringify(res.data.data));
                    location="index.html";
                }else{
                    alert("用户名或密码错误!");
                }
            })
            return false;
        }
    </script>
</body>
</html>